package service;

import java.util.List;
import java.util.Map;

import org.junit.BeforeClass;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.ccc.dao.UserLineDao;
import com.ccc.model.Line;
import com.ccc.model.Product;
import com.ccc.model.User;
import com.ccc.model.UserLine;
import com.ccc.service.LineService;
import com.ccc.service.UserLineService;
import com.ccc.service.UserService;
import com.ccc.util.dao.UtilDao;

public class LineServiceTest {
	
	private static LineService lineService;
	private static UserService userService;
	private static UtilDao utilDao;
	private static UserLineService userLineService;
	private static UserLineDao userLineDao;


	@BeforeClass
	public static void setUpBeforeClass() throws Exception {
		ApplicationContext ac = new  ClassPathXmlApplicationContext("beans.xml");
		lineService = (LineService) ac.getBean("lineService");
		utilDao = (UtilDao) ac.getBean("utilDao");
		userLineService = (UserLineService)ac.getBean("userLineService");
		userService = (UserService) ac.getBean("userService");
	}

	@Test
	public void testUpdateLine() {
		Line line = new Line();
		
		Product product = new Product();
		product.setProductId(29);
		
		line.setLineId(7);
		line.setProduct(product);
		line.setLineName("ssss");
		line.setLargeCapacity(100);
		line.setLargePrice(1);
		line.setLineBuyPrice(2);
		line.setLineCapacity(3);
		line.setLineRentPrice(8);
		lineService.deleteLine(line);
	}
	
	@Test
	public void deleteLine(){
		lineService.deleteLine(utilDao.find(Line.class, 7));
	}
	
	@Test
	public void testGetEveryUserLine(){
		User user = userService.findUser(1);
		List<UserLine> list = userLineService.listUserLine(user);
		Map<Line,Integer> map = userLineService.getEveryLineCapacity(list);
		System.out.println(map.toString());
	}
	
	@Test
	public void addUserLine(){
		UserLine userLine = new UserLine();
		userLine.setCurrentTime(0);
		userLine.setIsBuy(true);
		
		userLineDao.addUserLine(userLine);
	}
	
}
